package com.zjp.mapper;

import com.zjp.pojo.Reservation;
import com.zjp.pojo.ReservationExample;

import java.util.List;

import com.zjp.vo.ISiteAndVaccVo;
import com.zjp.vo.ReservationVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface ReservationMapper {
    long countByExample(ReservationExample example);

    int deleteByExample(ReservationExample example);

    int deleteByPrimaryKey(Integer id);
    /**
     * 更新预约接种状态
     *
     * @param
     * @return
     */
    int insert(Reservation record);

    int insertSelective(Reservation record);

    List<Reservation> selectByExample(ReservationExample example);

    List<Reservation> selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") Reservation record, @Param("example") ReservationExample example);

    int updateByExample(@Param("record") Reservation record, @Param("example") ReservationExample example);

    int updateByPrimaryKeySelective(Reservation record);

    int updateByPrimaryKey(Reservation record);

    /**
     * 更新预约接种记录状态
     *
     * @param id
     */
    @Update("update zjp.reservation set status = 0 where id = #{id}")
    void updateStuts(Reservation id);

    /**
     * 更新取消预约状态
     *
     * @param id
     * @return
     */
    @Update("update zjp.reservation set status = 2 where id = #{id}")
    int updateCancelStuts(int id);

    /**
     * 查询接种记录
     *
     * @param
     * @return
     */
    @Select("select * from zjp.reservation")
    List<ReservationVo> findAllReservationHist();

    /**
     * 查找预约接种
     *
     * @param
     * @return
     */
    @Select("SELECT i.id, r.vaccinesname, v.manufactor, i.inventory, r.inoculationname, r.starttime, r.endtime " +
            "FROM zjp.inoculation_history h " +
            "JOIN zjp.reservation r ON h.InoculationId = r.InoculationId " +
            "JOIN zjp.vaccines v ON v.vaccinesId = r.vaccinesId " +
            "JOIN zjp.i_vaccines i ON i.vaccinesId = v.vaccinesId " +
            "WHERE h.UserId = #{UserId}")
    public List<ReservationVo> selectByPrimaryKey1(Integer UserId);

//
//    /**
//     * 添加预约接种
//     * @param reservationVo
//     * @return
//     */
//    @Insert("Insert Into zjp.reservation (vaccinesname,inoculationname,starttime,endtime,reservationTime) values (#{vaccinesname},#{inoculationname},#{starttime},#{endtime},#{reservationTime})" )
//    int addReservation(Reservation reservationVo);




    /**
     * 查询导航栏
     *
     * @param
     * @return
     */
//    @Select("SELECT v.vaccinesName, r.inoculationname, v.manufactor, r.starttime  \n" +
//            "FROM zjp.vaccines v  \n" +
//            "JOIN zjp.reservation r ON v.vaccinesId = r.vaccinesId  \n" +
//            "WHERE v.vaccinesname LIKE CONCAT('%', #{vaccinesname}, '%')  \n" +
//            "  AND r.inoculationname LIKE CONCAT('%', #{inoculationname}, '%')  \n" +
//            "  AND v.manufactor LIKE CONCAT('%', #{manufactor}, '%')  \n" +
//            "  AND r.starttime > #{starttime};")
    List<ISiteAndVaccVo> findById(ISiteAndVaccVo iSiteAndVaccVo);
    /**
     * 插入预约接种状态
     *
     * @param
     * @return
     */
   @Insert("insert into zjp.reservation (id, vaccinesid, vaccinesname, InoculationId, inoculationname, starttime, endtime, reservationTime, userId, status) values (#{id}, #{vaccinesid}, #{vaccinesname}, #{inoculationid}, #{inoculationname}, #{starttime}, #{endtime}, #{reservationtime}, #{userid}, #{status}) " )
    int insert1(Reservation reservation);

    /**
     * 更新预约接种状态
     *
     * @param
     * @return
     */
    @Update("update zjp.reservation  set status = 0")
    int updateStuts1(Reservation reservation);
}